﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VirtualTournaments.Services;

namespace VirtualTournaments.Frontend
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            TextBoxUserName.Focus();
        }

        protected void ButtonLogIn_Click(object sender, EventArgs e)
        {
            // TODO: call user validation from services
            Services.Users.User user = Services.Users.UsersService.getUser(TextBoxUserName.Text);

            if (TextBoxUserName.Text.Equals(user.name) && TextBoxPassword.Text.Equals(user.password))
            {
                Session.Add("UserName", user.name);
                Session.Add("UserLogin", user.account);
                Session.Add("CurrentUser", user);
                Response.Redirect("VirtualTournaments.aspx");
            }
            else
            {
                LoginFailedMessageLabel.BackColor = System.Drawing.Color.CadetBlue;
                LoginFailedMessageLabel.Text = "Login failed!";
            }
        }
    }
}
